<template>
  <div class="remarks-style">
    <t-image-viewer v-model:visible="ImgVisible" :images="[getLinkUrl(ImgUrl)]"> </t-image-viewer>
    <div
      class="remarks-style-content"
      :style="{
        backgroundImage: `url(${publicUrls + 'free/style14/popup-windowBg.webp'})`,
      }"
    >
      <div class="close-box" @click="close">
        <span class="iconfonts">&#xe60e;</span>
      </div>
      <img class="top-left icons" :src="publicUrls + 'free/style14/popup-windowIcon.png'" alt="" />
      <img class="top-right icons" :src="publicUrls + 'free/style14/popup-windowIcon.png'" alt="" />
      <img class="bottom-left icons" :src="publicUrls + 'free/style14/popup-windowIcon.png'" alt="" />
      <img class="bottom-right icons" :src="publicUrls + 'free/style14/popup-windowIcon.png'" alt="" />
      <div class="content-box">
        <scrollBox
          color="rgba(51, 51, 51, 1)"
          v-if="Scrollheights && store.exhibitsInfoShow"
          :byid="200"
          :height="getScrollWComputed"
          :topFlag="flag"
          :scroll-src="publicUrls + 'free/style14/scrollIcon.png'"
        >
          <template #solidBorderCon>
            <exhibitsTop @addExId="selectInit" :info="Exinfo" @view-img="viewImg" />
            <!-- 展品描述 -->
            <div class="exhibits-describe" v-if="(Exinfo.audio && Exinfo.audio.url) || Exinfo.description">
              <div class="jointly-title">
                <span>展品描述</span>
              </div>
              <div class="description-text" v-if="Exinfo.description" v-html="Exinfo.description"></div>
              <div class="audeo-parent" v-if="Exinfo.audio && Exinfo.audio.url">
                <playAudio
                  v-if="!store.isMobileType"
                  :descriptionColor="'#FFF'"
                  :playColor="'rgba(53, 134, 243, 0.50)'"
                  :timeColor="'#3586F3'"
                  :iconColor="'#3586F3'"
                  :nameColor="'#3586F3'"
                  :background="'rgba(0, 22, 102, 0.50)'"
                  :name="Exinfo.audio.name"
                  :url="Exinfo.audio.url"
                  :description="Exinfo.audio.description"
                />
                <wapPlayAudio
                  v-else
                  :descriptionColor="'#FFF'"
                  :playColor="'rgba(53, 134, 243, 0.50)'"
                  :timeColor="'#3586F3'"
                  :iconColor="'#3586F3'"
                  :nameColor="'#3586F3'"
                  :background="'rgba(0, 22, 102, 0.50)'"
                  :name="Exinfo.audio.name"
                  :url="Exinfo.audio.url"
                  :description="Exinfo.audio.description"
                />
              </div>
            </div>
            <!-- 相关展品 -->
            <div class="beExhibits" v-if="moduleExhibits?.length !== 0">
              <div class="jointly-title">
                <span>相关展品</span>
              </div>
              <div class="exList">
                <div class="exBox" v-for="(item, index) in moduleExhibits" :key="index" @click="ExList(item?.id)">
                  <img class="ex-top-left ex-icons" :src="publicUrls + 'free/style14/exhibitsIcon.png'" alt="" />
                  <img class="ex-top-right ex-icons" :src="publicUrls + 'free/style14/exhibitsIcon.png'" alt="" />
                  <img class="ex-bottom-left ex-icons" :src="publicUrls + 'free/style14/exhibitsIcon.png'" alt="" />
                  <img class="ex-bottom-right ex-icons" :src="publicUrls + 'free/style14/exhibitsIcon.png'" alt="" />
                  <div class="exImg-box">
                    <img
                      :src="$filters.getLinkUrl(item?.coverUrl, '?imageView2/3/w/560/format/webp')"
                      alt=""
                      class="empty-img"
                    />
                  </div>
                  <div class="exTitle">
                    {{ item.name }}
                  </div>
                </div>
              </div>
            </div>
          </template>
          <template #solidBorderEx>
            <div class="solidBorder-child"></div>
          </template>
        </scrollBox>
      </div>
    </div>
  </div>
  <div class="select-box">
    <!-- placement="center" -->
    <t-dialog
      header="添加展品至展览"
      :visible="visibleStep"
      :confirm-on-enter="true"
      :on-cancel="closetables"
      :on-close="closetables"
      :cancelBtn="null"
      :confirmBtn="null"
    >
      <template #body>
        <t-row :gutter="16" style="width: 100%">
          <t-col :span="12">
            <div class="hw-dialog-box">
              <span class="titles">请选择展览:</span>
              <div class="hw-dialog-box-select">
                <t-select v-model="projectId" placeholder="请选择展览">
                  <t-option :key="item.id" :label="item.name" :value="item.id" v-for="item in selectInitList" />
                </t-select>
              </div>
            </div>
          </t-col>
        </t-row>
      </template>
      <template #footer>
        <t-button @click="visibleStep = false" theme="default" variant="outline">取消</t-button>
        <t-button @click="okStep">确定</t-button>
      </template>
    </t-dialog>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
  name: 'style14',
});
</script>
<script lang="ts" setup>
import { MessagePlugin } from 'tdesign-vue-next';
import { addExhibits } from '@/api/desgin/desgin';
import { getHeardToken } from '@/api/utils';
import { projectLists } from '@/api/project/project';
import { urls, getLinkUrl } from '@/utils/request/upload';
import { showToast, showImagePreview } from 'vant';
import exhibitsTop from './component/exhibitsTop.vue';
import playAudio from './component/audio.vue';
import wapPlayAudio from './component/audiowap.vue';
import { publicUrls } from '@/utils/minxin';
import { useProjectStore } from '@/store';
import { reactive, ref, watch, computed } from 'vue';
import { exhibitShowpiece } from '@/api/templates/templates';
import { moduleShowpieces } from '@/api/desgin/desgin';
import scrollBox from '../scrollBox.vue';

const emits = defineEmits(['viewImg']);
const store = useProjectStore();
const Exinfo = ref({}) as any;
const Scrollheights = ref();
const moduleExhibits = ref([]);
const selectInitList = ref();
const flag = ref(false);
const ImgUrl = ref('');
const WaplookList = ref([]);
const showpieceid = ref(store.exhibitsShowpieceid); // 选中展品的id
const ImgVisible = ref(false);
const projectId = ref(null);
const visibleStep = ref(false);
const loading = ref(false);
const parmas = reactive({
  pageSize: 999,
  pageNo: 1,
  id: store.exhibitsModuleId, // 展览id
  value: '',
  projectId: localStorage.getItem('projectId'),
});

const props = defineProps({
  info: {
    type: Object,
  },
  list: {
    type: Object,
  },
});

let viewportHeight = window.innerHeight;
Scrollheights.value = viewportHeight * 458;
const getScrollWComputed = computed(() => {
  let rootNode = document.documentElement;

  // 获取计算后的样式
  let computedStyle = window.getComputedStyle(rootNode);

  // 读取字体大小（注意这里返回的可能是一个包含单位的字符串，如"16px"）
  let fontSize = computedStyle.fontSize;

  // 如果你需要一个数字值（不带单位）进行计算，你可能需要解析这个字符串
  // 例如，使用正则表达式或split()方法去除单位，并将结果转换为数字
  let fontSizeNumber = parseFloat(fontSize.replace(/[^0-9.-]/g, ''));
  let heights = (fontSizeNumber / 144) * 458;
  return heights;
});
const getTabmComputed = computed(() => {
  let rootNode = document.documentElement;

  // 获取计算后的样式
  let computedStyle = window.getComputedStyle(rootNode);

  // 读取字体大小（注意这里返回的可能是一个包含单位的字符串，如"16px"）
  let fontSize = computedStyle.fontSize;

  // 如果你需要一个数字值（不带单位）进行计算，你可能需要解析这个字符串
  // 例如，使用正则表达式或split()方法去除单位，并将结果转换为数字
  let fontSizeNumber = parseFloat(fontSize.replace(/[^0-9.-]/g, ''));
  let heights = (fontSizeNumber / 144) * 98;
  return heights;
});

const close = () => {
  store.exhibitsInfoShow = false;
};

const init = async () => {
  // 获取选中展品
  let { data } = await exhibitShowpiece(parmas.id, showpieceid.value);
  Exinfo.value = data;
  // console.log(Exinfo.value, '123');
  // 获取单元所有展品
  let res = await moduleShowpieces(parmas);
  WaplookList.value = [];
  moduleExhibits.value = res.data.data;
  Exinfo.value.images.unshift({
    data: Exinfo.value.coverUrl,
    type: -1,
  });
  Exinfo.value.images.forEach((element) => {
    let url = getLinkUrl(element.data);
    WaplookList.value.push(url);
  });
  // console.log(moduleExhibits.value, '123');
};
init();

const ExList = (id: number) => {
  showpieceid.value = id;
  parmas.id = store.exhibitsModuleId;
  flag.value = !flag.value;
  setTimeout(() => {
    init();
  }, 0);
};

const viewImg = (url: string, indexs?: number) => {
  if (store.isMobileType) {
    ImgUrl.value = getLinkUrl(url);

    emits('viewImg', WaplookList.value, indexs ? indexs : 0);
  } else {
    ImgUrl.value = url;
    ImgVisible.value = true;
  }
};
const selectInit = async () => {
  try {
    let res = await projectLists(props.info.id);
    if (res.data.length > 0) {
      selectInitList.value = res.data;
      visibleStep.value = true;
      // console.log(selectInitList.value);
    } else MessagePlugin.warning('暂无可添加的展览');
  } catch (err) {
    console.log(err);
  }
};
const addId = () => {
  let token = getHeardToken();
  if (!token) {
    // ElMessageBox.alert('是否前往登录？', '您暂未登录', {
    //   confirmButtonText: '确定',
    //   callback: (action: Action) => {
    //     if (action === 'confirm') {
    //       pathSubmitClick();
    //     }
    //   },
    // });
    // visibleMessage.value = true;
    store.loginModeShow = true;
    return;
  }
  selectInit();
};
const okStep = async () => {
  try {
    if (loading.value) {
      return;
    }
    if (projectId.value) {
      loading.value = true;
      let res = await addExhibits(projectId.value, Exinfo.value.id, [Exinfo.value.id]);
      if (res.succeeded) {
        MessagePlugin.success('添加成功');
      }

      loading.value = false;
      visibleStep.value = false;
      projectId.value = null;
    } else {
      MessagePlugin.success('请选择展览');
      return;
    }
  } catch {
    loading.value = false;
  }
};
const closetables = (context?: any): void => {
  visibleStep.value = false;
};
watch(
  () => store.exhibitsInfoShow,
  () => {
    showpieceid.value = store.exhibitsShowpieceid;
    parmas.id = store.exhibitsModuleId;
    flag.value = !flag.value;
    setTimeout(() => {
      init();
    }, 0);
  },
);
</script>

<style lang="less" scoped>
::v-deep .unit-exbit-null-remarks-info {
  min-height: 100% !important;
}
::v-deep .solid-box-parent {
  position: absolute;
  right: -50px;
  top: 50%;
  transform: translateY(-50%);
  img {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    margin-top: 0 !important;
  }
}
::v-deep .templatestyle1-scroll-box-tumb {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.solidBorder-child {
  width: 2px;
  height: 100%;
  flex-shrink: 0;
  background: #113bac;
}
.remarks-style {
  display: flex;
  flex-direction: column;
  position: relative;
  //   width: 100%;
  max-width: 1200px;
  width: 1200px;
  height: 750px;
  background: transparent;
  transform: translateZ(0px);
}
.remarks-style-content {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background-repeat: no-repeat;
  background-size: 100% 100%;
}
.close-box {
  cursor: pointer;
  position: absolute;
  top: 0;
  right: -10px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  .iconfonts {
    font-size: 28px;
    color: #d4bb8f;
    flex-shrink: 0;
  }
}
.icons {
  position: absolute;
  width: 14px;
  height: 14px;
  object-fit: cover;
}
.top-left {
  top: 36px;
  left: 34px;
  transform: rotate(-90deg);
}
.top-right {
  top: 36px;
  right: 34px;
}
.bottom-left {
  bottom: 34px;
  left: 35px;
  transform: rotate(180deg);
}
.bottom-right {
  bottom: 34px;
  right: 35px;
  transform: rotate(90deg);
}
.content-box {
  width: 1200px;
  height: 620px;
  display: flex;
  justify-content: center;
  padding: 0 98px;
}
.exhibits-describe {
  margin-top: 40px;
  width: 100%;
}
.jointly-title {
  color: #3586f3;
  text-align: center;
  font-family: 'SourceHanSerifCN';
  font-size: 24px;
  font-style: normal;
  font-weight: 700;
  line-height: 40px; /* 166.667% */
}
.description-text {
  margin-top: 16px;
  color: #fff;
  text-align: justify;
  font-family: 'PingFang SC';
  font-size: 16px;
  font-style: normal;
  font-weight: 400;
  line-height: 32px; /* 200% */
  text-indent: 32px;
  ::v-deep(p) {
    margin-top: 16px;
    color: #fff;
    text-align: justify;
    font-family: 'PingFang SC';
    font-size: 16px;
    font-style: normal;
    font-weight: 400;
    line-height: 32px; /* 200% */
    text-indent: 32px;
  }
}
.audeo-parent {
  margin: 20px 0;
  :deep(.player-parent) {
    border-radius: 8px;
    border: 1px solid #3586f3;
  }
  :deep(.infoShow-box) {
    margin: 0;
    border-radius: 0;
    padding: 0 30px 20px 30px;
    text-indent: 32px !important;
  }
  :deep(.infoShow-box::before) {
    content: '';
    display: block;
    width: 100%;
    height: 1px;
    background: #3586f3;
    margin-bottom: 20px;
  }
  :deep(.player-box) {
    border-radius: 0;
  }
  :deep(.left-box) {
    .doorIcon {
      font-size: 46px;
    }
  }
  :deep(.right-bottom-left),
  :deep(.right-bottom-right) {
    font-size: 20px;
  }
  :deep(.t-slider__rail) {
    height: 2px !important;
    border-radius: 26px !important;
    background: rgba(53, 134, 243, 0.5) !important;
  }
  :deep(.t-slider__button) {
    width: 14px !important;
    height: 14px !important;
    background-color: #3586f3 !important;
    border: none !important;
  }
  :deep(.t-slider__track) {
    height: 2px !important;
    background-color: #3586f3 !important;
  }
}
.beExhibits {
  width: 100%;
  margin-top: 20px;
}
.exList {
  width: 100%;
  margin-top: 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
}
.exBox {
  position: relative;
  width: 300px;
  height: 400px;
  border-radius: 16px;
  border: 2px solid #d4bb8f;
  background: radial-gradient(78.25% 76.86% at 50% 23.14%, #0054d4 0%, #002c6e 100%);
  margin-bottom: 42px;
  padding: 30px 0 24px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
}
.exBox:nth-child(3n + 2) {
  margin: 0 52px;
}
.ex-icons {
  position: absolute;
  width: 40px;
  height: 40px;
  object-fit: fill;
}
.ex-top-left {
  top: 10px;
  left: 10px;
}
.ex-top-right {
  top: 10px;
  right: 10px;
  transform: rotate(90deg);
}
.ex-bottom-left {
  bottom: 10px;
  left: 10px;
  transform: rotate(-90deg);
}
.ex-bottom-right {
  bottom: 10px;
  right: 10px;
  transform: rotate(180deg);
}
.exImg-box {
  flex-shrink: 0;
  width: 246px;
  height: 290px;
  border-radius: 16px;
  border: 2px solid #d4bb8f;
  overflow: hidden;
  .empty-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: all 0.5s;
  }
}
.exImg-box:hover {
  .empty-img {
    transform: scale(1.2);
  }
}
.exTitle {
  flex-shrink: 0;
  width: 234px;
  color: #fff;
  text-align: center;
  font-family: 'SourceHanSerifCN';
  font-size: 18px;
  font-style: normal;
  font-weight: 500;
  line-height: 180%; /* 32.4px */
  margin-top: 24px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.select-box {
  :deep(.t-dialog) {
    padding: 0;
    background: transparent;
    border: none;
  }
  :deep(.t-dialog__header) {
    display: flex !important;
  }
  :deep(.t-dialog__footer) {
    display: flex !important;
  }
  :deep(.t-dialog) {
    max-height: 286px;
    padding: 0;
    background: #fff !important;
    z-index: 9999 !important;
  }
  :deep(.t-dialog__header) {
    display: initial;
    display: flex;
  }
  :deep(.t-dialog__footer) {
    display: initial;
    display: flex;
    justify-content: flex-end;
  }
  :deep(.t-dialog__body) {
    padding: 12px 32px !important;
    overflow: visible;
    display: flex;
    justify-content: center;
    align-content: center;
  }
  :deep(.titles) {
    margin-bottom: 6px;
  }
}
</style>
